package com.zhuss.advice.processor;

import com.zhuss.advice.db.dao.ext.ComplaintDao;
import com.zhuss.advice.db.entity.Complaint;
import com.zhuss.bean.bo.advice.Complaint.CreateComplaintBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.ComplaintType;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;
import com.zhuss.util.NoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/6 14:53
 */
@Component("complaintCreate")
public class ComplaintCreate extends AbstractProcessor<Object, CreateComplaintBo> implements Processor<Object, CreateComplaintBo> {

    @Autowired
    private ComplaintDao complaintDao;

    @Override
    public Object process(CreateComplaintBo bo) throws WpsException {
        Complaint c = new Complaint();
        c.setComplaintNo(NoUtil.TS + NoUtil.gen());
        c.setTel(bo.getTel());
        c.setContent(bo.getContent());
        c.setComplaintKey(bo.getComplaintKey());
        c.setStatus(ComplaintType.已提交.key());
        c.setArea(bo.getConcurrentArea());

        c.setCreator(bo.getConcurrentUserName());
        c.setCreatorId(bo.getConcurrentUserId());
        c.setCreateTime(new Date());
        complaintDao.create(c);
        return null;
    }

    @Override
    public Object log(CreateComplaintBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.意见建议.key());
        record.setAction(LogActionEnum.投诉创建.key());
        record.setTargetId(param.getTargetId());
        record.setTargetName(param.getComplaintNo());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(CreateComplaintBo bo) throws WpsException {

    }
}
